﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.HomeServer.Controls.QSM;
using WhsFacebook.Net.Contracts;

namespace WhsFacebook.Whs.Service.Submitters
{
    public sealed class DisksSubmitter : InfoSubmitter<IEnumerable<WhsDiskInfo>>
    {
        #region instance

        public static DisksSubmitter Instance
        {
            get; private set;
        }

        static DisksSubmitter()
        {
            Instance = new DisksSubmitter();
        }

        #endregion

        protected override IEnumerable<WhsDiskInfo> DoSubmitInternal()
        {
            var disks = QSMMgr.GetDisks();
            var r = new List<WhsDiskInfo>();

            foreach (var d in disks)
            {
                r.Add(new WhsDiskInfo()
                {
                    BusType = d.BusType.ToString(),
                    Capacity = d.Capacity,
                    DiskId = d.ID,
                    DiskModel = d.Name,
                    DiskRole = d.Role.ToString(),
                    FreeSpace = d.FreeSpace,
                    IsExternal = d.IsExternal,
                    Location = d.Location,
                    UsedSpace = d.UsedSpace,
                    WhsDiskInfoId = d.SystemId,
                });
            }

            // submit
            using (var wc = new WhsFacebookServiceClientFactory())
            {
                wc.CreateChannel().UpdateDisks(WhsFacebookRegistry.GetInstanceId(), r);
            }

            return r;
        }

        private DisksSubmitter()
        {
            
        }
    }
}
